package com.demo.commcial.controller;


import com.demo.commcial.entity.AdminOper;
import com.demo.commcial.entity.ParkProject;
import com.demo.commcial.mapper.AdminOperMapper;
import com.demo.commcial.mapper.ParkProjectMapper;
import com.demo.commcial.service.impl.AdminOperServiceImpl;
import com.demo.commcial.service.impl.ParkProjectServiceImpl;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author admin
 * @since 2020-10-25
 */
@Controller
@RequestMapping("/parkProject")
public class ParkProjectController {

    @Resource
    ParkProjectServiceImpl parkProjectServiceImpl;

    @Resource
    ParkProjectMapper parkProjectMapper;

    // 查询所有列
    @RequestMapping("list")
    public String list(Model model){
        List<ParkProject> parkProject = parkProjectMapper.selectList(null);
        model.addAttribute("parkProject",parkProject);
        return "parkproject/list";
    }

    //添加页面跳转
    @RequestMapping("add")
    private String add(){
        return "parkproject/add";
    }

    //添加
    @RequestMapping("addParkProject")
    private String addUsers(Model model,ParkProject parkProject){
        int i= parkProjectMapper.insert(parkProject);
        model.addAttribute("u",i);
        return "redirect:/parkProject/list";
    }

    //删除
    @RequestMapping("delete/{projectId}")
    private String deleteUsers(@PathVariable("projectId") Integer id){
        parkProjectMapper.deleteById(id);
        return "redirect:/parkProject/list";
    }

    //跳转修改页面
    @RequestMapping("update/{projectId}")
    private String updateUsers(@PathVariable("projectId")Integer id,Model model){
        ParkProject parkProject=parkProjectMapper.selectById(id);
        model.addAttribute("parkProject",parkProject);
        return "parkproject/update";
    }

    //修改
    @RequestMapping("update")
    private String update(ParkProject parkProject){
        parkProjectServiceImpl.saveOrUpdate(parkProject);
        return "redirect:/parkProject/list";
    }

}

